﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using LastLandClient.Data;

using Up2Link.SegString;

namespace LastLandClient.Core.CmdInterpreter
{
    public class CCmdBuild : ICommandInterpreter
    {
        public void ExecuteCommand(string _cmd, string _args)
        {
            if (_args != null)
            {
                String[] args = _args.Split(CConst.DELIMITER_ARGUMENT);
                if (args.Length == 1 && CData.clientConnected)
                {
                    String arg = args[0].ToLowerInvariant().Trim();
                    Int32 msgCode = 0;
                    switch (arg)
                    {
                        case "farm":
                            msgCode = CConst.CLIENT_MESSAGE_BUILD_FARM;
                            break;
                        case "mine":
                            msgCode = CConst.CLIENT_MESSAGE_BUILD_MINE;
                            break;
                        case "village":
                            msgCode = CConst.CLIENT_MESSAGE_BUILD_VILLAGE;
                            break;
                        case "fort":
                            msgCode = CConst.CLIENT_MESSAGE_BUILD_FORT;
                            break;
                        case "city":
                            msgCode = CConst.CLIENT_MESSAGE_BUILD_CITY;
                            break;
                        case "granary":
                            msgCode = CConst.CLIENT_MESSAGE_BUILD_GRANARY;
                            break;
                        case "forge":
                            msgCode = CConst.CLIENT_MESSAGE_BUILD_FORGE;
                            break;
                        case "market":
                            msgCode = CConst.CLIENT_MESSAGE_BUILD_MARKET;
                            break;
                        case "courthouse":
                            msgCode = CConst.CLIENT_MESSAGE_BUILD_COURTHOUSE;
                            break;
                        default:
                            break;
                    }

                    if (msgCode != 0)
                    {
                        CMessageSS buildMsg = new CMessageSS(msgCode, 0, CMessageSS.ENCODING_UTF32, "");
                        CData.client.Send(buildMsg);
                    }
                    else
                    {
                        CData.console.SendOutput("参数" + arg + "无效");
                        CData.console.SendOutput("build:farm|mine|village|fort|city|granary|forge|market|courthouse");
                    }
                }
                else if (args.Length != 1)
                {
                    CData.console.SendOutput("build指令接受一个参数");
                }
                else if (!CData.clientConnected)
                {
                    CData.console.SendOutput("玩家尚未连接服务器");
                }
                else
                {
                    CData.console.SendOutput("无效的指令");
                }
            }
            else
            {
                CData.console.SendOutput("无效的指令");
            }
        }
    }
}
